#include <gtest/gtest.h>
#include <iostream>

/*
    断言宏的使用
        ASSERT_ : 断言失败直接返回
        EXPECT_ : 断言失败继续执行
    注意：断言宏只能在 TEST 宏函数中使用
*/
// TEST(test, less_than){
//     int x = 10;
//     ASSERT_LE(x, 20);
//     printf("OK!");
// }

// TEST(test, greter_than){
//     int x = 10;
//     ASSERT_GT(x, 20);
// }

// int main(int argc, char* argv[])
// {
//     testing::InitGoogleTest(&argc, argv);
//     RUN_ALL_TESTS();
//     return 0;
// }


class MyEnvironment: public testing::Environment{
public:
    virtual void SetUp() override{
        std::cout << "单元测试环境初始化" << std::endl;
    }
    virtual void TearDown() override{
        std::cout << "单元测试环境清理" << std::endl;
    }
};

TEST(MyEnvironment, 1){
    int x = 10;
    ASSERT_LE(x, 0);
}
TEST(MyEnvironment, 2){
    int x = -1;
    ASSERT_LE(x, 0);
}
std::string str;
class MyEnvironment2: public testing::Environment{
public:
    virtual void SetUp() override{
        std::cout << "单元测试环境初始化" << std::endl;
    }
    virtual void TearDown() override{
        std::cout << "单元测试环境清理" << std::endl;
    }
};

TEST(MyEnvironment2, 1){
    ASSERT_LE(str.size(), 0);
    str += 'a';
}
TEST(MyEnvironment2, 2){
    ASSERT_LE(str.size(), 0);
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MyEnvironment);
    testing::AddGlobalTestEnvironment(new MyEnvironment2);
    RUN_ALL_TESTS();
    return 0;
}